#include <cstdlib>
#include "AutoAlbumMaker.h"
#include "Renderer.h"
#include "PDFRenderer.h"
#include "Directory.h"

using namespace std;
using namespace AAM;

/*
 * 
 */
int main(int argc, char** argv) {
    if(argc < 2){
        cout << endl << "insuficient number of arguments";
        return 1;
    }
    
    int show=0;
	bool selection = true;
    string directory(argv[1]);
	string outputFilename("saida.pdf");
    int pageWidth = 800;
    int pageHeight = 600;
	int numberOfPages = -1;
    int read = 2;
    while(read < argc){
        string command(argv[read]);
        if(command.compare("-s")==0){
                 show = 1;
        }else if(command.compare("-n")==0){
		selection = false;
        }else if(command.compare("-nPages")==0){
                if(read+1 >argc-1){
                    cout << endl << "Parameter -nPages needs an integer value.";
                    return 1;
                }
                string nPages(argv[++read]);
                numberOfPages = atoi(nPages.c_str());
        }else if(command.compare("-w")==0){
                if(read+2 >argc-1){
                    cout << endl << "Parameter -w needs two integer values.";
                    return 1;
                }
                string width(argv[++read]);
                string height(argv[++read]);
                pageWidth = atoi(width.c_str());
                pageHeight = atoi(height.c_str());

            
        }else if(command.compare("-o")==0){
            if(read+1 > argc-1){
                cout << endl << "Parameter -o needs one value.";
                return 1;
            }
             outputFilename = argv[++read];
        }else{
                cout << endl << "Usage: \t-s : shows result";
                cout << endl << "\t-w <WIDTH> <HEIGHT>: Defines page dimension";
                cout << endl << "\t-o <output_filename> : defines output file path";
                return 1;
        }
        read++;
    }
    Directory dir(directory.c_str());
    AutoAlbumMaker aam;
    aam.setPageDimensions(pageWidth,pageHeight);
    Renderer *renderer = new PDFRenderer();
	renderer->setOutputFilename(outputFilename);
    aam.setRenderer(renderer);
    aam.setImagePathList(dir.getFileNames());
	aam.setSelection(selection);
	aam.setMaxNumberOfPages(numberOfPages);
    
    aam.generateAlbum();
    return 0;
}

